<?php
/**
 * Created by PhpStorm.
 * User: zcq
 * Date: 2018/10/23
 * Time: 13:44
 */

namespace app\admin\controller;


use app\admin\service\CommentService;

class Comment extends Base
{
    public $commentService;
    public function __construct(CommentService $commentService)
    {
        parent::__construct();
        $this->commentService = $commentService;
    }

    public function index()
    {
        $keyword = input('keyword');
        $status = input('status');
        $auto = input('auto');

        $data = $this->commentService->getPagination($status,$auto,$keyword);
        $this->assign('data',$data);
        $this->assign('keyword',$keyword);
        $this->assign('status',$status);
        $this->assign('auto',$auto);
        return $this->fetch();
    }

    public function ajaxUpdate()
    {
        $field = input('field');
        $value = input('value');
        $id = input('id');
        if($field == 'enable')
            $value = (int) $value;
        $res = $this->commentService->update($id,[$field=>$value,'modtime'=>time()]);
        if($res){
            echo api_return(1,'保存成功');
        }else{
            echo api_return(0,'保存失败');
        }
    }
}